<?php
require('functions.php');
if(isset($_POST['submit'])){
	require('clases/variable.class.php');
	$objVariables=new Variables;
	
	$variable_id = htmlspecialchars(trim($_POST['variable_id']));
	$var1 = htmlspecialchars(trim($_POST['var1']));	
	$valor = htmlspecialchars(trim($_POST['valor']));	
		
	if ( $objVariables->actualizar(array($var1,$valor),$variable_id) == true){
		echo 'Datos guardados';
	}else{
		echo 'Se produjo un error. Intente nuevamente';
	} 
}else{
	if(isset($_GET['id'])){
		
		require('clases/variable.class.php');
		$objVariables=new Variables;
		$consulta = $objVariables->mostrar_variable($_GET['id']);
		$variable = mysql_fetch_array($consulta);
	?>
	<form id="frmVariableActualizar" name="frmVariableActualizar" method="post" action="actvariable.php" onsubmit="ActualizarVariable(); return false;">
    	<input type="hidden" name="variable_id" id="variable_id" value="<?php echo $variable['id']?>" />
        <p>
	  <label>Variable<br />
	  <input class="text" type="text" name="var1" id="var1" value="<?php echo $variable['var']?>" maxlength="50" />
	  </label>
      </p>
	  <p>
		<label>Descripci&oacute;n<br />
         <input class="text" type="text" name="valor" id="valor" value="<?php echo $variable['valor']?>" maxlength="100" />	
		</label>
	  </p>
	 
	  <p>
		<input type="submit" name="submit" id="button" value="Enviar" />
		<label></label>
		<input type="button" name="cancelar" id="cancelar" value="Cancelar" onclick="Cancelar()" />
	  </p>
	</form>
	<?php
	}
}
?>